﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace WyCash
{
    public  class Money:Expression
    {
        protected internal int amount;
        protected string currency;
        public Money(int amount, string currency)
        {
            this.amount = amount;
            this.currency = currency;
        }

        public  Expression times(int multiplier) 
        { return new Money(amount*multiplier,currency); }

        public string Currency()
        { return currency; }

        public bool equals(Money money)
        {
            return amount == money.amount && Currency().Equals(money.Currency());
        }

        public String tostring()
        { return amount + " " + currency; }


        internal static Money dollar(int amount)
        {
            return new Dollar(amount, "USD");
        }

        internal static Money franc(int amount)
        {
            return new Franc(amount, "CHF");
        }


        public Expression plus(Expression addend)
        {
            return new Sum(this, addend);
        }

        public Money reduce(Bank bank, string to)
        {
            int rate = bank.rate(currency, to);
            return new Money(amount/rate,to); 
        }
    }
}
